<?php
namespace App\Admin\Renderable;
use App\Admin\Repositories\WxTask;
use App\Wen\Utils\FieldUtils;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class DayTaskRender extends LazyRenderable
{
    public function grid(): Grid
    {
        return Grid::make(new WxTask(), function (Grid $grid) {
            global $__MINI_GLOBAL_TENANT_ID__;
            if($__MINI_GLOBAL_TENANT_ID__ > 0){
                $grid->model()->where('tenant_id', '=', $__MINI_GLOBAL_TENANT_ID__);
            }
            $grid->model()->where('type', '=', 0);
            $grid->quickSearch(['id','name'])->placeholder('搜索任务ID，名字...');
            $grid->model()->orderBy('id', 'desc');
            $grid->column('id')->sortable();
            $grid->column('name', '名字');
            $grid->column('type', '类型');
            $grid->column('condition_type_0', '条件类型')->using(FieldUtils::getDayTaskTypes());
            $grid->column('condition_num', '条件数量');
            $grid->column('reward_type', '奖励类型')->using(FieldUtils::getGiftTypes());
            $grid->column('reward_num', '奖励数量');
            $grid->column('target_type', '跳转类型')->using(FieldUtils::getUrlTypes());
            $grid->column('target_id', '跳转ID');
//            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
            $grid->disableBatchActions();
            $grid->disableActions();
        });
    }
}
